﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace ReceiptTracker
{
    public partial class FormMontlyAvg : Form
    {
        private SQLiteDB db;
        private PieChart chart;
        public FormMontlyAvg(SQLiteDB db)
        {
            InitializeComponent();
            this.db = db;
            db.SQLQuery("SELECT ROUND(AVG(spent),2) AS average,SUBSTR(month,1,4) AS year FROM (SELECT ROUND(SUM(spent),2) AS SPENT," +
                " SUBSTR(date,1,7) AS month FROM Receipts GROUP BY month) GROUP BY year");
            chart = new PieChart(this.CreateGraphics(), "Monthly Average", "kr");
            foreach (DataRow row in db.QueryResult.Rows)
            {
                chart.AddItem(Convert.ToDouble(row["average"]), row["year"].ToString());
            }
        }

        private void FormMontlyAvg_Paint(object sender, PaintEventArgs e)
        {
            chart.DrawChart(10, 10, 300, 300);
        }
    }
}
